package com.dhy.dao;

import com.dhy.dbCore.util.DbUtil;
import com.dhy.dbCore.JdbcTemplateFacade;
import com.dhy.domain.Course;
import com.dhy.dto.CourseDto;
import com.dhy.dto.CourserMajorDto;

import java.util.List;

/**
 * @author 大忽悠
 * @create 2022/6/7 10:34
 */
public class CourseDao {

    private JdbcTemplateFacade jt= DbUtil.getJT();

    public List<CourseDto> queryStudByCno(String cno) {
          String sql="SELECT c.name courseName,c.type,s.sno,s.name,sc.score,sc.makeUpScore,sc.rebuildScore\n" +
                  "FROM stu s\n" +
                  "INNER JOIN courseSelection sc\n" +
                  "ON s.id=sc.sid\n" +
                  "INNER JOIN course c\n" +
                  "ON c.id=sc.cid\n" +
                  "WHERE c.id='"+cno+"'";
        return jt.list(sql, CourseDto.class);
    }

    public Boolean deleteCourse(String cid) {
        String sql="delete from course where id = '"+cid+"';";
        return jt.delete(sql);
    }

    public List<CourserMajorDto> list() {
      String sql="SELECT c.id,c.name,c.type,c.credits,m.name majorName FROM course c INNER JOIN major m ON c.majorId=m.id";
      return jt.list(sql, CourserMajorDto.class);
    }

    public Boolean insert(Course course) {
        String sql="INSERT course VALUES(NULL,"+course.getType()+","+course.getCredits()+","+
                course.getMajorId()+",'"+course.getName()+"')";
        return jt.insert(sql);
    }
}
